﻿<%@ Page Language="C#" AutoEventWireup="true" Buffer="false" CodeBehind="DesktopMain.aspx.cs" Inherits="ZX.WebApp.DeskTop.Form.DesktopMain" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>    
    <link href="styles/css.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/deskTopStyle.css" rel="stylesheet" type="text/css" />    
    <script src="Scripts/json2.js" type="text/javascript"></script>
    <script src="Scripts/CustomFunction.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../../KM/FullTextSearch/Script/CommonJS.js" type="text/javascript"></script>
</head>
<body>
    <!--异常考勤提醒begin-->
    <div id="div_wk" class="custom_clum_wk" style="display:none;cursor:move;" onmousedown="startMove(event)" onmouseup="stopMove(event)">
        <span class="paneltitle" style="float:left;font-size:23px; color:#FFFF33; margin-top:15px; margin-left:15px;" id="tId"><b>异常考勤提醒 </b></span>
        <div class="clum_tools">
            <img id="img_btnwk_close" style="position:relative;margin-top:13px; margin-right:7px;padding-top:10px;cursor:pointer;" src="../../Images/Peixun/cancel.gif"  title="关闭"/>
        </div>
        <div id="msgaddid" style=" margin-left:110px; margin-top:75px;overflow-y:auto; width:620px; height:90px;">
        <div id="MsgId">
            <div style="color: Red; font-size:20px; font-family:幼圆;font-weight:bolder;">
                请在4日24点前确认上月考勤,无误后系统将自动给您核算考勤工资,<br/>未确认则视作默认系统现有结果!
            </div>
            <a href="#" onclick="javascript:fnOpenDetail();fnHideDivWk();" title="点击查看异常考勤明细">您有【<span id="spworkResultNum" style="color: Red; font-size:25px;"></span>】条待确认的异常考勤记录</a>
        </div>
       </div>
    </div>
    <!--异常考勤提醒end-->
    <form id="form1" runat="server">
        <!--主体 开始-->
        <div class="custom_clum_box">
            <!--左边框-->
            <div class="custom_clum_left"></div>
        
            <!--右边框-->
            <div class="custom_clum_right" id="div_default_right"></div>

            <div class='custom_clum_right_2' id='fix_right_div'></div>
        </div>
        <!--主体 结束-->

    </form>

</body>
</html>

<script type="text/javascript">
    var chartNum = 0;
    var userHasRight = <%=getRight %>;

    var tempData = [], loadNumber = 2, tempLoadNumber = 8; //loadNumber：滑下去加载两个，tempLoadNumber：默认加载8个。
    var custom_clum_left = $(".custom_clum_left"); //左边容器
    var custom_clum_right = $("#div_default_right"); //右边容器
    var fix_right;

    //  ID： clum_tools_reload_+ id  刷新按钮
    var refreshBtn_Html = "<li class='ul_li_buttons refresh' style='width:25px;'><img class='clum_tools_reload' src='styles/images/refresh.png' /></li>";
    //  ID：clum_tools_more_+id      更多按钮
    var moreBtn_Html = "<li class='ul_li_buttons more' style='width:45px;color:#6CA6CD;'><a href='javascript:void(0)' class='clum_tools_more' >更多..<a/></li>";

    var Lock = false;

    $(function () {
        Lock = false;
        custom_clum_left = $(".custom_clum_left");
        custom_clum_right = $("#div_default_right");
        custom_clum_left.html(""); custom_clum_right.html("");

        loadData();

        $(".ClassFromCRM").live("click", function () {
            var cobj = $(this);
            var km_index = cobj.attr("KmIndex");
            var _data = cobj.attr("CRMObj");
            window.open(km_index + "?KM_DATA=" + _data);
        });

        //动态注册tab按钮事件   Tab按钮
        $(".tab").live("click", function () {
            changeTab($(this));
        });
        //动态注册tab按钮事件   刷新按钮
        $(".clum_tools_reload").live("click", function () {
            alert("刷新");
        });
        //动态注册tab按钮事件   更多按钮
        $(".clum_tools_more").live("click", function () {
            var moreUrl = $(this).attr("moreUrl");
            var title = $(this).attr("moreTitle");
            parent.addTabs(title, moreUrl);
        });

        $("#img_btn_close").live("click", function () {
            $("#div_default_right").show();
            $("#fix_right_div").animate({ opacity: 'hide' }, { duration: 200, queue: true });
        });

        var fix_right_html = "" +
        "    <table border='0' cellpadding='0' cellspacing='0'style='width:100%;height:100%;'>" +
        "        <tr>" +
        "            <td valign='top' class='clum_big_center'>" +
        "                <div class='load_title' id='Rankid'>" +
        "                    <span class='paneltitle' style='float:left; cursor: pointer; color:red;' onclick='totalRank(0)' opSgin='0'>销售业绩排名</span>" +
//        "                    <span class='paneltitle' style='float:left; margin: 0px 3px;'>|</span>" +
//        "                    <span class='paneltitle' style='float:left; cursor: pointer' onclick='totalRank(1)' opSgin='1'>价值业绩排名</span>" +
        "                    <span class='paneltitle' style='float:left; margin: 0px 3px;'>|</span>" +
        "                    <span class='paneltitle' style='float:left; cursor: pointer' onclick='totalRank(2)' opSgin='2'>交付排名</span>" +
        "                    <div class='clum_tools'>" +
        "                        <img id='img_btn_close' style='position:relative;top:-2px;*top:-2px;padding-top:10px;cursor:pointer;' src='../../Images/Peixun/cancel.gif' />" +
        "                    </div>" +
        "                </div>" +
        "                <div style='clear:both;'></div>" +
        "                <div id='div_tab' class='clum_content' style='background-color:White;overflow:auto;'><iframe id='if_fix' frameborder='0' style='height:100%;width:100%;border:0px;overflow:hidden;'></iframe></div>" +
        "            </td>" +
        "        </tr>" +
        "    </table>";

        $("#fix_right_div").html("");
        $("#fix_right_div").append(fix_right_html);

        setTimeout(function () {//延迟加载
            if(userHasRight == 1){
                $("#if_fix").attr("src", "../../Crm/Report/Pop-PubPage.aspx?type=0");
            }
        }, 3000);

        setTimeout(function () {//延迟加载
            if(userHasRight == 1){
                $("#fix_right_div").animate({ opacity: 'show' }, { duration: 1, queue: true });
                $("#div_default_right").hide();
            }else{
                $("#div_default_right").show();
                $("#fix_right_div").hide();
            }
        }, 5000);
    });

    /*滚动到底部的时候触发*/
    $(window).bind("scroll", function () {
        if ($(document).scrollTop() + $(window).height() > $(document).height() - 10) {
            //loadNumber：滑下去加载两个，tempLoadNumber：默认加载6个。
            
            beginLoadDeskTopPanelData(false);
        }
    });

    //tab切换事件，更改tab焦点
    var changeTab = function (event) {
        event.parent().find("li").each(function () {
            $(this).removeClass("ul_li_active");
        })

        event.addClass("ul_li_active");
        var TabUrl = event.attr("TabUrl");
        var TabPro = event.attr("TabPro");
        var TabFunction = event.attr("TabFunction");
        var MoreUrl = event.attr("MoreUrl");
        var title = event.html();
        var __id = event.attr("id");
        __id = __id.split("_")[1];
        __id = __id.split("$")[0];
        var eventParent = event.parent().parent().parent();
        var powerType = eventParent.attr("powerType");
        var pageType = eventParent.attr("pageType");

        var moreBtn = eventParent.find(".clum_tools_more");
        moreBtn.attr("moreUrl", MoreUrl);
        moreBtn.attr("moreTitle", title);

        if (TabPro == null) TabPro = "";
        if (TabPro != "") TabPro = "&" + TabPro;

        if (TabUrl.indexOf("?") > 0) TabUrl += "&powerType=" + powerType + TabPro;
        else TabUrl += "?powerType=" + powerType + TabPro;

        if (pageType == "1") {
            var myiframeObj = eventParent.parent().find(".iframe_ccccc");
            LoadDataFromAjaxOrIframe(myiframeObj, TabUrl, "1");
        } else { //div
            var c = eventParent.parent().parent().find(".clum_content_div");
            LoadDataFromAjaxOrIframe(c, TabUrl, "0");
        }

        var fun = event.attr("TabFunction");
        if (fun == null || fun == undefined || fun == "") return;


        //异常捕获，如果该函数未定义，则报错。
        try {
            window[fun](event); //执行自定义tab事件
        }
        catch (e) {
            alert("自定义函数有问题，检查是否已经定义了改函数");
        }
    };

    var loadData = function () {
        $.getJSON("DesktopMain.aspx?Action=LoadData&r=" + Math.random(), function (data) {
            tempData = data;
//            var __tempHeight = 120;
//            var _win_height = $(window).height();

//            var __leftCount = 1;
//            var __rightCount = 1;

//            $.each(tempData, function (i, mm) {
//                if (mm.Region == "center") {
//                    if (__leftCount * __tempHeight < _win_height) {
//                        __leftCount = Number(__leftCount) + Number(1);
//                    }
//                }
//                if (mm.Region == "right") {
//                    if (__rightCount * __tempHeight < _win_height) {
//                        __rightCount = Number(__rightCount) + Number(1);
//                    }
//                }
//            });
//            if (__leftCount >= __rightCount) tempLoadNumber = __leftCount;
//            else tempLoadNumber == __rightCount;
            beginLoadDeskTopPanelData(true);
        });
    };

    var beginLoadDeskTopPanelData = function (IsInit) {
        if (Lock) return;
        if (tempData == undefined) { alert("没有数据加载!"); Lock = true; return; }
        //loadNumber：滑下去加载两个，tempLoadNumber：默认加载6个。
        if (IsInit) {
            for (var i = 0; i < tempLoadNumber; i++) {
                if (tempData.length > i) {
                    var m = tempData[i];
                    if (m == null || m == undefined) continue;
                    var region = m.Region;
                    createLeftPanel(m, region);
                }
            }
            if (tempData.length < tempLoadNumber) Lock = true;
        }
        else {
            for (var j = 0; j < loadNumber; j++) {
                if (tempData.length > tempLoadNumber) {
                    var m = tempData[tempLoadNumber];
                    var region = m.Region;
                    createLeftPanel(m, region);
                    tempLoadNumber += 1;
                } else {
                    Lock = true;
                }
            }
        }

        resizeWidth();
    };

    $(window).resize(function () {
        resizeWidth();
    });

    var resizeWidth = function () {
        var w = $(window).width();

        var r_w = 0;
        var fix_right_div = $("#fix_right_div");
        
        if (userHasRight == 1) {
            fix_right_div.width(custom_clum_right.width()-3);
            r_w = custom_clum_right.width()+2;
        } else {
            r_w = custom_clum_right.width();
        }
        fix_right_div.height(custom_clum_left.height()-12);
        $("#div_tab").height(fix_right_div.height() - 10);
        custom_clum_left.width(w - r_w - 2);
    };

    //动态创建桌面
    var createLeftPanel = function (data, region) {
        var deskTopModel = "";
        var deskTopModelID = "list_panel" + data.id;
        deskTopModel = "<div id=" + deskTopModelID + " class='list_panel'>" +
            "<table border='0' cellpadding='0' cellspacing='0' style='width:100%;height:100%;'>     " +
            "    <tr valign='top'>                                                                               " +
            "        <td valign='top'><img src='styles/images/load_bk_left.png' /></td>             " +
            "        <td valign='top' class='clum_big_center'>                                      " +
            "            <div class='load_title'  powerType=" + data.powerType + " pageType=" + data.pageType + " src=" + data.src + " >                                                   " +
            "                <span class='paneltitle' style='float:left;'></span>                   " +
            "                <div class='clum_tools'>                                               " +
            "                    <ul></ul>                                                          " +
            "                </div>                                                                 " +
            "            </div>                                                                     " +
            "            <div id='clum_content_id_" + data.id + "' class='clum_content'>";

        if (data.pageType == "1") {
            deskTopModel += "<iframe width='100%' class='iframe_ccccc' frameborder='0' scrolling='auto'></iframe>";
        }
        else {
            deskTopModel += "<div class='clum_content_div'></div>";
        }

        deskTopModel += "</div>" +
            "        </td>                                                                          " +
            "        <td valign='top'><img src='styles/images/load_bk_right.png' /></td>            " +
            "    </tr>                                                                              " +
            "</table></div>";
        //clum_content  容器中需要添加以下三个东西  iframe与div  是根据判断来加载的
        //<center style="display: none" class="load_img">栏目加载中...</center>
        //<iframe width="100%" src="http://www.baidu.com/" frameborder="0" height="180px;" scrolling="auto"></iframe>
        //<div></div>

        var deskTopModelObj = $(deskTopModel);
        deskTopModelObj.find(".paneltitle").html(data.title)

        var toolsPanel = deskTopModelObj.find("ul");
        var toolsObj = $(data.tools);
        toolsPanel.append(toolsObj);
        var activeTools = toolsPanel.find(".ul_li_active")
        //activeTools.attr("islive", "1");

        var moreObj = toolsPanel.find(".clum_tools_more");

        if (activeTools.length > 0) {
            moreObj.attr("moreUrl", activeTools.attr("MoreUrl"));
            moreObj.attr("moreTitle", activeTools.html());
        } else {
            moreObj.attr("moreUrl", data.more);
            moreObj.attr("moreTitle", data.title);
        }

        var panelObj; //容器对象
        if (region == null || region == "") region = "center";
        if (region == "center") {
            panelObj = custom_clum_left;
        } else {
            panelObj = custom_clum_right;
            //deskTopModelObj.find(".tab").remove();
        }
        panelObj.append(deskTopModelObj); //容器中添加子容器

        var contentObj = $("#clum_content_id_" + data.id);
        var url = data.src;
        if (activeTools.length != undefined && activeTools.length > 0) url = activeTools.attr("TabUrl");

        var TabPro = activeTools.attr("TabPro");
        if (TabPro == null) TabPro = "";
        if (TabPro != "") TabPro = "&" + TabPro;

        if (url.indexOf("?") > 0) {
            url += "&powerType=" + data.powerType + TabPro;
        } else {
            url += "?powerType=" + data.powerType + TabPro;
        }

        if (data.pageType == "1") {//页面方式展示
            var myiframeObj = contentObj.find(".iframe_ccccc");
            LoadDataFromAjaxOrIframe(myiframeObj, url, "1");
        } else {
            var c = contentObj.find(".clum_content_div");
            LoadDataFromAjaxOrIframe(c, url, "0");
        }
    };

    //加载
    var LoadDataFromAjaxOrIframe = function (contentObj, url, pageType) {
        if (url.indexOf("?") > 0) url += "&r=" + Math.random();
        else url += "?r=" + Math.random();

        if (pageType == "1") {
            contentObj.attr("src", url); //iframe
        }
        else {
            $.ajaxSetup({
                error: function (x, e) {
                    var myError = x.responseText;
                    contentObj.html(myError);
                }
            });

            $.getJSON(url, function (data) {
                contentObj.html(data);
            });
        }
    };

    var fnOpenDetail = function () {
        parent.parent.addTabs("考勤确认", "../../Extend/YUIDataTableList.aspx?entity=V_wkWorkResult&order=WorkDate desc&functionID=46b2b874-c1ce-4807-a5f1-5a08b57699b3&condition=IsValidate='N' and WkStatus not in ('正常出勤','非工作日','项目中','加班')");
    };


    var fnOpenDeptDetail = function () {
        parent.parent.addTabs("我的部门人员加班", "../../EditWidows/eYUITreeList.aspx?IsSelfHelp=true&IsOnlyMyDept=true&IsDisplayChild=true&entity=V_wkOvertimeLeaveTotal&order=LDeptName,CName&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath&ForeignKey=DeptID&functionID=9594e537-c15d-4481-afb7-e4a172539869");
    };

    var ViewDeptChart = function () {
        var url = "../../Extend/Reports/hrDeskReports.aspx?flag=deptEmpCount&r=" + Math.random();
        var pagetitle = "在职人数统计";
        parent.parent.addTabs(pagetitle, url);
        parent.parent.NeedRefreshPage = this;
    };

    var fnOpenDetailLocation = function () {
        window.location = "../../Extend/YUIDataTableList.aspx?entity=V_wkWorkResult&order=WorkDate desc&functionID=46b2b874-c1ce-4807-a5f1-5a08b57699b3&condition=IsValidate='N' and WkStatus not in ('正常出勤','非工作日','项目中','加班')";
    }

    var fnOpenDeptDetailLocation = function () {
        window.location = "../../EditWidows/eYUITreeList.aspx?IsSelfHelp=true&IsOnlyMyDept=true&IsDisplayChild=true&entity=V_wkOvertimeLeaveTotal&order=LDeptName,CName&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath&ForeignKey=DeptID&functionID=9594e537-c15d-4481-afb7-e4a172539869";
    }

    var ShowAnnounce = function (title, announceId) {
        parent.parent.addTabs(title, "http://" + this.location.host + "/EditWidows/SysManager/ShowAnnounce.aspx?ID=" + announceId + "&r=" + Math.random() + "");
    }
    var fn_ShowMoreMessage = function () {
        parent.parent.addTabs("更多消息", "../../Extend/YUIList.aspx?entity=V_Message&order=SendTime desc&functionID=3fa9d909-c7c1-4dae-91a7-be904d4d905e");
    }
    var fn_ShowHistoryMessage = function () {
        parent.parent.addTabs("查看历史消息", "../../Extend/YUIList.aspx?entity=V_MessageHistory&order=SendTime desc&functionID=3fa9d909-c7c1-4dae-91a7-be904d4d905e");
    }

    //1-4号异常考勤提醒begin
    $(document).ready(function () {
        fnGetWorkResult();

        //课程转换提示功能合并到考勤异常信息当中 ,2013-12-11,wangjihui,394594745@qq.com
        TransOrderMsg();
    });

    var fnHideDivWk = function(){
        $("#div_wk").hide();
    }
    var fnShowDivWk = function(){
        $("#div_wk").show();
    }
    $("#img_btnwk_close").live("click",function(){
        $("#div_wk").hide();
    });

    //课程转换提醒客户经理 ,2013-12-11,wangjihui,394594745@qq.com
    function TransOrderMsg()
    { 
       var url = "/Extend/AjaxData/JSONList.aspx"; 
        $.ajax({
            type: "GET",
            dataType: "json",
            url: url,
            data: { onlyTotal: "true", entity: "V_HF_TaskInstanceView",functionid:"8E3F1DF7-DCA8-4110-9446-5E8F9EAC9AAF", output:"json",customCondition:encodeURI("WorkFlowId='235ba9ad-c7b2-4aa9-b1c4-3861f760a1e5'"),order:"taskStartTime desc"},
            success: function (data) { 
                if (data != null && data != undefined) {
                  var isdisplay= ($("#div_wk").css("display")=="none"); //隐藏，也就是没有异常考勤信息
                  var total=data[0].total;
                   if(total>0)
                   {
                    //标题信息
                     var _title="<B>信息提示</B>";
                     var _display= "";
                     var _margintop="margin-top:15px;";
                     if(isdisplay)
                      {
                        _title="<B>课程转换信息提示</B>";
                        //没有异常考勤数据，隐藏提示数据 
                        _display="none";
                        _margintop="";
                      } 

                     $("#MsgId").css("display",_display); 
                     $("#tId").html(_title)

                     //信息内容
                     var _html="<div style=\""+_margintop+"\">"+
                        "<div style=\"color: Red; font-size:20px; font-family:幼圆;font-weight:bolder;\">"+
                            "您有课程转换信息尚未确认，请及时确认！"+
                        "</div><a href=\"javascript:;\" onclick=\"javascript:fnOpenTransOrderInfo();\" title=\"点击查看课程转换信息\">您有【<span style=\"color: Red; font-size:25px;\">"+total+"</span>】条待确认的记录</a>"+
                       "</div>";  
                    $("#msgaddid").append(_html);

                     fnShowDivWk();
                   }
                }
            },
            error: function (e) {
                return;
            }
        }
      );
  
  }

  //点击查看信息
  function fnOpenTransOrderInfo()
  {
     fnHideDivWk(); 
     parent.parent.addTabs("待办任务", "/Extend/YUIList.aspx?entity=V_HF_TaskInstanceView&functionID=8E3F1DF7-DCA8-4110-9446-5E8F9EAC9AAF&condition=WorkFlowId='235ba9ad-c7b2-4aa9-b1c4-3861f760a1e5'&order=taskStartTime desc");
     
  } 


    var totalRank = function(type)
    { 
       //设置选中Tabs的字体颜色 wangjihui,394594745@qq.com
       $("#Rankid").find("span").each(function(item){
           var _f=$(this).attr("opSgin");
           if(_f!="" &&_f!= undefined)
           {
             if(type==_f)
               $(this).css("color","red");
             else
               $(this).css("color","");
           } 
       });

       //调用不同页面 wangjihui,394594745@qq.com
       var url="/Crm/Report/Pop-PubPage.aspx?type="+ type;
       if(type==2)
       {
         url="/Crm/Report/RptDeliverOrder.aspx";
       }
       $("#if_fix").attr("src",url);
    }

    var fnGetWorkResult=function(){
            $.get("../../EHR/workTimeAjax.aspx?flag=GetWorkResult&r=" + Math.random(), 
            { frmday:"1",endday:"5" },
              function(data){
                    var workResultNum=0;
                     workResultNum =parseInt(data);
                        //alert(workResultNum);
                       //debugger
                        if (workResultNum > 0)
                        { 
                            fnShowDivWk();
                           $("#spworkResultNum").html(workResultNum);
                        }
              });
    }
    //1-4号异常考勤提醒end

    //移动、调整DIV大小begin
    var offset_x;
    var offset_y;
    var oX, oY, oLeft, oTop; //存储原始移动前的位置
    function startMove(oEvent) {
        var switchButton;
        //0没按键    1按左键   2按右键 3按左和右键 4按中间键   5按左和中间键 6按右和中间键    7按所有的键
        if (oEvent.button == 1)//event.button返回当事件被触发时，哪个鼠标按钮被点击
        {
            switchButton = true;
        }

        if (switchButton) {
            //debugger;
            var mElement = document.getElementById('div_wk');
            mElement.setCapture();
            //clientX 返回当事件被触发时，鼠标指针的水平坐标。
            //offsetX 发生事件的地点在事件源元素的坐标系统中的 x 坐标和 y 坐标。
            //offset_x = parseInt(oEvent.clientX - mElement.offsetLeft); //移动之前鼠标相对于被移动元素的X偏移
            //offset_y = parseInt(oEvent.clientY - mElement.offsetTop);
            oX = parseInt(oEvent.clientX);
            oY = parseInt(oEvent.clientY);
            oLeft = parseInt(mElement.offsetLeft);
            oTop = parseInt(mElement.offsetTop);
            mElement.onmousemove = function () {
               var m = document.getElementById('div_wk');
               var x= event.clientX;
               var y= event.clientY;
                m.style.left = (x) + "px"; ;
                m.style.top = (y) + "px";
            }
        }
    }

    function stopMove(oEvent) {
        var mElement = document.getElementById('div_wk');
        mElement.releaseCapture();
        mElement.onmousemove = null;
    }
    //移动、调整DIV大小end
  </script>